﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NutriLeaf.Web.Model;

namespace NutriLeaf.Web.Core.Account
{
    public class Account
    {
        public static LoginStatus LogIn(string accesstoken, DateTime expires,ref NutriLeafDBEntities context)
        {
                if (String.IsNullOrEmpty(accesstoken))
                {
                    throw new Exceptions.Account.AccessTokenEmptyException("Access token is Empty");
                }

                if (DateTime.Now > expires)
                {
                    throw new Exceptions.Account.AccessTokenExpiredException("Access token is Expired");
                }

                User user = new User(accesstoken, expires, ref context);
                LoginStatus status;
                if (user.IsRegistered())
                {
                    status = LoginStatus.Success;
                }
                else
                {
                    status = LoginStatus.Registered;
                }

                user.UpdateUserProfile();  //upddate user profile from facebook

                return status;

        }
    }
}